package com.itheima.mobile;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConstant;
import com.itheima.entity.Result;
import com.itheima.pojo.Setmeal;
import com.itheima.service.SetmealService;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @description:
 * @author: dalao
 * @date: 2020/4/10-14:49
 * @Version: 1.0.0
 */
@RestController
@RequestMapping("/setmeal")
public class MobileSetmealController {
    @Reference
    private SetmealService setmealService;

    @RequestMapping("/getSetmeal")
    private Result getSetmeal(String token){
//        让redis校验token,如果没有登录让用户去登录
        try {
            List<Setmeal> setmealList = setmealService.getSetmeal();
            return Result.OK(MessageConstant.GET_SETMEAL_LIST_SUCCESS,setmealList);
        }catch (Exception e){
            e.printStackTrace();
            return Result.ERROR(MessageConstant.GET_SETMEAL_LIST_FAIL);
        }
    }
    @RequestMapping("/findById")
    public Result findById(@RequestParam("id") String id){
        try{
            Setmeal setmeal = setmealService.findById(id);
            return Result.OK("",setmeal);
        }catch (Exception e){
            e.printStackTrace();
            return Result.ERROR(MessageConstant.QUERY_SETMEAL_FAIL);
        }
    }
}
